<template>
  <div>
    <el-dialog title="常量项信息" :visible.sync="dialogVisible" @close="close">
      <el-form :model="data" :rules="rules" ref="form" label-width="120px">
        <el-form-item label="名称" prop="name" label-width="120px">
          <el-input v-model="data.name"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer">
        <el-button @click="close">取 消</el-button>
        <el-button type="primary" @click="save">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import { changeBaseconstById } from "@/api/dictionary";
export default {
  watch: {
    data() {
      console.log(this.data);
    }
  },
  data() {
    return {
      data: {},
      dialogVisible: false,
      rules: {
        name: [{ required: true, message: "请输入", trigger: "blur" }]
      }
    };
  },
  methods: {
    close() {
      this.dialogVisible = false;
    },
    show(data) {
      this.data = JSON.parse(JSON.stringify(data));
      this.data.baseConstId = this.data.id;
      this.dialogVisible = true;
    },
    save() {
      this.$refs["form"].validate(async valid => {
        if (valid) {
          let r = await changeBaseconstById(this.data);
          if (r && r.error == 0) {
            this.$refs["form"].resetFields();
            this.$emit("finish", this.data.zbasetype.id);
            this.close();
          } else {
            this.$message({
              message: "出错了",
              type: "error"
            });
          }
        } else {
          return false;
        }
      });
    }
  }
};
</script>
